#ifndef MIDI_H_
#define MIDI_H_

#include "../controller/threading.h"
#include <fstream.h>
#include <iostream.h>

class MidiHandler {
public:
	virtual ~MidiHandler(){}
	virtual void handle(int channel,int value)=0;
};

class MidiReader : public Runnable {
private:
	std::string device;
	MidiHandler *handler;
public:
	MidiReader(std::string _device){
		device = _device;
		handler=0;
	}
	void setHandler(MidiHandler *_handler) {
		handler = _handler;
	}
	void run() {
		//Alpbach
		char buffer[2];
		ifstream myFile (device.data(), ios::in | ios::binary);


		while (myFile.read (buffer, 2)) {
			printf("received MIDI byte: %d %d  \n", buffer[0], buffer[1]);
			if (handler!=0) {
				handler->handle(buffer[0],buffer[1]);
			}
		}
	}
};


#endif /*MIDI_H_*/
